package com.zs4sdk.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.common.library.util.ActivityHelper;
import com.common.library.util.Helper;
import com.zs4sdk.activity.resetPassword.Zs4GameResetPasswordActivity;
import com.zs4sdk.common.Extra;
import com.zs4sdk.entity.Zs4GameData;
import com.zs4sdk.entity.Zs4GamePersonInfoEntity;

import org.json.JSONObject;

/**
 * Created by Administrator on 2018/4/24.
 */
//com.zs4sdk.activity.Zs4GameAccountCenterActivity
public class Zs4GameAccountCenterActivity extends Zs4GameAcountCenterActivityBase {
    protected String mPhoneNumber = "";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mRelIdVerifyLoyout.setVisibility(View.GONE);
        //ActivityHelper.getIdResId("zs4gameviewid_rel_payrecord")

    }
    @Override
    protected void init() {
        super.init();
        if(Extra.isComplex()){
            setTopTitle(ActivityHelper.getStringResId("zs4gameAccountCenterTitle"));
            TextView textView = findView(TextView.class, ActivityHelper.getIdResId("zs4gameviewid_txv_safe_phone_bind_label"));
            TextView tvBind = findView(TextView.class, ActivityHelper.getIdResId("zs4gameviewid_txv_safe_phone_bind"));
            textView.setText(ActivityHelper.getStringResId("zs4gameAccountUpgrade"));
            tvBind.setText(ActivityHelper.getStringResId("zs4gameUpgrade"));
            ImageView img = findView(ImageView.class, ActivityHelper.getIdResId("zs4gameviewid_imv_safe_phone_bind_label"));
            img.setImageDrawable(getResources().getDrawable(ActivityHelper.getImageResId("zs4gameicon_account")));
        }
    }

    protected  void dePersonInfoSuccess(Message msg){
        Zs4GamePersonInfoEntity personInfoEntity = new Zs4GamePersonInfoEntity((JSONObject) msg.obj);
        if (personInfoEntity.isSuccess()) {
            if(isComplex()){
                doPersonInfoSuccessFt(personInfoEntity);
            }else{
                doPersonInfoSuccess(personInfoEntity);
            }
        } else {
            mRelSafePhone.setClickable(false);
            //获取个人信息失败
        }
    }

    private boolean isComplex(){
        return Extra.isComplex();
    }
    protected void doPersonInfoSuccess(Zs4GamePersonInfoEntity personInfoEntity){
        mTxvNickname.setText("用户名："+ personInfoEntity.getNickname());
//                    NnbTextView.setText(personInfoEntity.getNnb()+"平台币");
        //手机是否绑定
        if (Helper.isEmpty(personInfoEntity.getMobile())) {
            mTxvPhoneBind.setText(ActivityHelper.getStringResId("zs4gamestring_account_ensure_update"));
            mTxvPhoneBind.setTextColor(Color.parseColor(mRedColor));
            mRelSafePhone.setClickable(true);
            //ActivityHelper.getIdResId("zs4gameviewid_rel_change_password")
            View view = findViewById(ActivityHelper.getIdResId("zs4gameviewid_rel_change_password"));
            //   view.setVisibility(View.GONE);
            //zs4gameviewid_lin_rebind_phone
            view.setEnabled(false);
        } else {
//                        mTxvNickname.setText("用户名："+ personInfoEntity.getMobile());
            mBindPhone = personInfoEntity.getMobile();
            mTxvPhoneBind.setText(ActivityHelper.setPhone(mBindPhone));
            mRelSafePhone.setClickable(false);
            mTxvPhoneBind.setTextColor(Color.parseColor(mBlackColor));
            View view = findViewById(ActivityHelper.getIdResId("zs4gameviewid_rel_change_password"));
            // view.setVisibility(View.VISIBLE);
            view.setEnabled(true);
            view =  findViewById(ActivityHelper.getIdResId("zs4gameviewid_lin_rebind_phone"));
            view.setVisibility(View.VISIBLE);
        }
    }
    protected void doPersonInfoSuccessFt(Zs4GamePersonInfoEntity personInfoEntity){//繁体处理
        View view = findViewById(ActivityHelper.getIdResId("zs4gameviewid_rel_change_password"));
        view.setEnabled(true);
    }

    // 到修改密码
    protected void goChangePasswordActivity() {
        Class<?> cls =  Zs4GamePhoneCheckActivity.class;
        if(isComplex()){
            cls = Zs4GameResetPasswordActivity.class;
        }
        Intent intent = new Intent(this, cls);
        intent.putExtra("phone",mBindPhone);
        intent.putExtra("classStyle",1);
        startActivity(intent);
       // startActivityForResult(intent, Extra.REQUESTCODE.CHAGEPASSWORD);
        //classStyle
    }

    protected void checkGuest(){
        if (Zs4GameData.getInstance().isGuest()){
            mRelSafePhone.setEnabled(true);
            View view = findView(RelativeLayout.class,ActivityHelper.getIdResId("zs4gameviewid_lin_change_password"));
            view.setVisibility(View.GONE);
            mTxvPhoneBind.setText(ActivityHelper.getStringResId("zs4gamestring_account_ensure_update"));
        }else {
            mRelSafePhone.setEnabled(false);
            View view = findViewById(ActivityHelper.getIdResId("zs4gameviewid_rel_payrecord"));
            view.setVisibility(View.GONE);
            if(isComplex()){
                mRelSafePhone.setVisibility(View.GONE);
            }
        }
    }
    // 到绑定安全手机
    protected void goBindSafePhone() {
        //Zs4GameBindSafeAccountActivity
        Class<?> cls = Zs4GameBindSafePhoneActivity.class;
        if(isComplex()){
            cls = Zs4GameBindSafeAccountActivity.class;
        }
        Intent intent = new Intent(this, cls);
        Bundle bundle = new Bundle();
        bundle.putInt(Extra.INTENTKEY.SCREEN_ORIENTATION, this.mScreenOrientation);
        bundle.putString(Extra.INTENTKEY.FLAG, flag);
        bundle.putInt(Extra.INTENTKEY.BIND_PHONE,Extra.REQUESTCODE.REQUEST_BIND_PHONE);
        intent.putExtras(bundle);
        startActivityForResult(intent, Extra.REQUESTCODE.REQUEST_BIND_PHONE);

    }

}
